package thread;

/*
 * @author zzr
 * @date: 2025/03/31  18:21
 * @description:
 */
class PrintNumberTask implements Runnable {
    private final int number;

    public PrintNumberTask(int number) {
        this.number = number;
    }

    @Override
    public void run() {
        System.out.println(number);
    }
}

public class ThreadDemo27 {
    public static void main(String[] args) {
        Thread[] threads = new Thread[20];
        // 创建 20 个线程
        for (int i = 0; i < 20; i++) {
            threads[i] = new Thread(new PrintNumberTask(i));
            // 启动线程
            threads[i].start();
        }

        // 等待所有子线程执行完毕
        for (Thread thread : threads) {
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        System.out.println("ok");
    }
}
